<template>
  <div class="user-info">

    <div class="grid-content bg-purple">

      <div class="b">
        <div style="overflow: hidden"></div>
        <span :style="{background: resultSpanBg}">{{ resultSpan }}</span>
      </div>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>成绩信息</span>
        </div>

        <div>
          <div class="name-role">
            <div class="warning-box" v-if="errorInfo !== ''">
              <p>{{ errorInfo }}</p>
            </div>
            <el-image
              style="width: 100px; height: 100px"
              :src="examInfo.photoUrl"
              :preview-src-list="imageList">
            </el-image>
            <span class="sender">姓名 - {{ examInfo.realName }}</span>
          </div>
          <div class="registe-info">
          <span class="registe-info">
            申请时间： {{ examInfo.createTime }}<br>
          </span>
          </div>
          <el-divider></el-divider>
          <div class="personal-relation" v-for="(value, key) in info" :key="key">
            <div class="relation-item">
              <span>{{ value }}:</span>
              <div>
                <span v-if="!key.includes('Url')">{{ examInfo[key] }}</span>
                <el-image
                  v-else
                  style="width: 100px; height: 100px"

                  :src="examInfo[key]"
                  :preview-src-list="imageList">
                </el-image>
              </div>
            </div>
          </div>
        </div>

      </el-card>
    </div>

  </div>
</template>

<script>
import {applyExamList} from '@/api/paper/exam'
import {getApplyExamAnon} from "@/api/paper/paper";

export default {
  name: 'QRCodePage',
  data() {
    return {
      errorInfo: '',
      examInfo: {},
      imageList: [],
      resultSpan: '有效结果',
      resultSpanBg: '#36A8FF',
      info: {
        realName: '姓名',
        phone: '手机号',
        idCard: '身份证号',
        companyName: '公司名称',
        jobType: '工种',
        workAreaName: '工作区域',
        entryTime: '入厂时间',
        leaveTime: '离厂时间',
        allPassTip: '是否通过',
        // createTime: '申请时间',
        healthProofUrl: '健康证明',
        noCriminalProofUrl: '无犯罪证明',
      },

      params: {
        userName: '',
        isApply: '1'
      }

    }

  },

  mounted() {
    this.params.userName = this.$route.params.userName || this.$route.fullPath.split('/').at(-1);
    this.params.userName = decodeURIComponent(this.params.userName);

    getApplyExamAnon(this.params).then(res => {
      if (res.data) {
        this.examInfo = res.data
        if (this.examInfo.allPass !== 2) {
          this.resultSpan = '无效结果';
          this.resultSpanBg = '#FF4D4F'; // 红色背景
          this.errorInfo = '考试未通过或未完成';
        }

        // 获取当前时间
        const currentTime = new Date();
        // 获取离场时间
        const leaveTime = this.examInfo.leaveTime;
        // 比较当前时间和离场时间
        if (leaveTime && currentTime > new Date(leaveTime)) {
          this.resultSpan = '无效结果';
          this.resultSpanBg = '#FF4D4F'; // 红色背景
          this.errorInfo = '申请结果已过期，请重新申请考试';
        }

        this.imageList = [
          this.examInfo.photoUrl,
          this.examInfo.healthProofUrl,
          this.examInfo.noCriminalProofUrl,
          this.examInfo.certificatePhotosUrl
        ].filter(url => url) // 过滤掉空的URL
      } else {
        this.errorInfo = '没有找到相关考试记录'
      }
    }).catch(() => {
      this.errorInfo = '没有找到相关考试记录'
    })
  }
}
</script>

<style lang="css" scoped>
.user-info {
  padding: 20px;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.box-card {
  width: 100%;
}

.name-role {
  font-size: 16px;
  padding: 5px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.sender {
  text-align: center;
}

.registe-info {
  text-align: center;
  padding-top: 10px;
}

.personal-relation {
  font-size: 16px;
  padding: 0px 5px 15px;
  margin-right: 1px;
  width: 100%
}

.relation-item {
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-footer {
  padding-top: 10px;
  padding-left: 10%;
}

.el-row {
  margin-bottom: 20px;

  &:last-child {
    margin-bottom: 0;
  }
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #99a9bf;
}

.bg-purple {
  background: #d3dce6;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
  position: relative;
  overflow: hidden;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.warning-box {
  border: 1.5px solid #e74c3c;
  background: #fdecea;
  color: #c0392b;
  padding: 16px 20px;
  border-radius: 6px;
  margin-bottom: 24px;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.warning-box p {
  margin: 0;
}

.b {
  width: 200px;
  height: 200px;
  position: absolute;
  /*background: green;*/
  top: -100px;
  right: -100px;
  transform: rotate(45deg);
  overflow: hidden;
}

.b span {
  position: absolute;
  bottom: 0;
  display: block;
  color: #fff;

  width: 200px;
  text-align: center;
  font-size: 18px;
  line-height: 40px;
  height: 40px;
}

</style>
